#version 410

layout (lines) in;
layout (triangle_strip, max_vertices = 4) out;

void main()
{
	vec2 pos2 = gl_in[0].gl_Position.xy;
	vec2 pos3 = gl_in[1].gl_Position.xy;
	vec2 pos1 = vec2(pos2.x,pos3.y);
	vec2 pos4 = vec2(pos3.x, pos2.y);

	if ( ( (pos3.x < pos2.x) && (pos3.y < pos2.y) ) || ( (pos3.x > pos2.x) && (pos3.y > pos2.y) ) )
	{
		vec2 temp = pos2;
		pos2 = pos3;
		pos3 = temp;
	}

    gl_Position = vec4(pos1,0.0,1.0);
    EmitVertex();
	gl_Position = vec4(pos2,0.0,1.0);
	EmitVertex();
	gl_Position = vec4(pos3,0.0,1.0);
	EmitVertex();
    gl_Position = vec4(pos4,0.0,1.0);
    EmitVertex();
    EndPrimitive();
} 